package com.eos.business.service;

import java.util.List;
import java.util.Map;

import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.DaoAccessObjectPoolContextFactory;
import com.eos.orm.c3p0.dao.AbstractC3p0Dao;
import com.eos.orm.c3p0.dao.impl.SysCustomerLinkDaoImpl;
import com.eos.orm.mybatis.dao.SysCustomerLinkMapper;
import com.eos.orm.mybatis.dao.SysCustomerMapper;
import com.eos.orm.mybatis.model.SysCustomer;
import com.eos.orm.mybatis.model.SysCustomerExample;
import com.eos.orm.mybatis.model.SysCustomerLink;
import com.hf.utils.PaginationBean;

public class SysCustomerBusinessService extends AbstractEosService<SysCustomer>{
	private SysCustomerMapper sysCustomerMapper =  (SysCustomerMapper) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("SysCustomerMapper");
	private SysCustomerLinkMapper customerLinkMapper = (SysCustomerLinkMapper) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("SysCustomerLinkMapper");
	private AbstractC3p0Dao<SysCustomerLink> sysCustomerLinkDAo = (SysCustomerLinkDaoImpl) DaoAccessObjectPoolContextFactory
		.getInstaAccessObjectPoolContext().instanceDataAccessObject("SysCustomerLinkDao");
	/**
	 * 保存客户信息
	 * @param customer
	 * @return
	 */
	public String saveCustomer(SysCustomer customer){ 
		return sysCustomerMapper.insert(customer) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 *更新客户部分信息
	 * @param customer
	 * @return
	 */
	public String updateCustomerSelective(SysCustomer customer){
		return sysCustomerMapper.updateByPrimaryKeySelective(customer) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 获取客户信息
	 * @param customerId
	 * @return
	 */
	public SysCustomer getSysCustomer(int customerId){
		return sysCustomerMapper.selectByPrimaryKey(customerId);
	}
	
	/**
	 * 查询系统中所有有效的客户信息<br>
	 * deal_flag: 0<br>
	 * status: 0
	 * @return
	 */
	public List<SysCustomer> getAllSyscutomer(){
		SysCustomerExample example = new SysCustomerExample();
		SysCustomerExample.Criteria cri = example.createCriteria();
		cri.andDealFlagEqualTo(ConstantTool.DEAL_FALG_OK);
		cri.andStatusEqualTo(ConstantTool.STATUS_OK);
		example.setOrderByClause(" id desc ");
		return sysCustomerMapper.selectByExample(example);
	}
	
	/**
	 * 保存客户联系信息
	 * @param scl
	 * @return
	 */
	public String saveCustomerLink(SysCustomerLink scl){
		return customerLinkMapper.insert(scl) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 修改客户联系信息的部分内容
	 * @param scl
	 * @return
	 */
	public String updateCustomerLinkSelective(SysCustomerLink scl){
		return customerLinkMapper.updateByPrimaryKeySelective(scl) == 0 ? "SUCCESS" : "FAIL";
	}
	
	/**
	 * 获取联系信息
	 * @param linkId
	 * @return
	 */
	public SysCustomerLink getCustomerLink(int linkId){
		return customerLinkMapper.selectByPrimaryKey(linkId);
	}
	
	/**
	 * 分页查询客户联系人信息
	 * @param map
	 * @return
	 */
	public PaginationBean getSysCustomerLinkList(Map<String, String> map){
		List<SysCustomerLink> customerLinkList = sysCustomerLinkDAo.findPage(map);
		PaginationBean pageBean = sysCustomerLinkDAo.findBean(map);
		pageBean.setResultList(customerLinkList);
		return pageBean;
	}
	
	
}
